import { MacroMonitor } from '@/monitor/macro_monitor'
import { MacroInspector } from '@/types/monitor'
import { MacroParamsProviderType } from '@/monitor/macro_monitor'
import { player } from './player'
import { vars } from './vars'
import {callStack} from './callStack'

// 监控器
export const monitor = new MacroMonitor((actionType: MacroParamsProviderType, name: string) => {
    switch (actionType) {
        case MacroParamsProviderType.Constructor: {
            switch (name) {
                case MacroInspector.Countdown:
                    return [
                        () => {
                            player.stopWithError(
                                new Error(
                                    `E351: macro '${callStack.peek().resource.name}' timeout ${vars.get('!TIMEOUT_MACRO')}s (change the value in the settings if needed)`
                                )
                            )
                        }
                    ]
                case MacroInspector.Timer:
                case MacroInspector.LoopTimer:
                default:
                    return []
            }
        }

        case MacroParamsProviderType.Restart: {
            switch (name) {
                case MacroInspector.Countdown:
                    return [
                        vars.get('!TIMEOUT_MACRO') * 1000,
                        true
                    ]
                case MacroInspector.Timer:
                case MacroInspector.LoopTimer:
                default:
                    return []
            }
        }
    }
})